package com.xmy.study.service.impl;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xmy.study.entity.ChaPlan;
import com.xmy.study.entity.EduQuarter;
import com.xmy.study.entity.Task;
import com.xmy.study.mapper.ChaPlanMapper;
import com.xmy.study.mapper.TaskMapper;
import com.xmy.study.service.IChaPlanService;
import com.xmy.study.service.IEduQuarterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

@Service
public class ChaPlanServiceImpl extends ServiceImpl<ChaPlanMapper, ChaPlan> implements IChaPlanService {

    @Autowired
    @Lazy
    ChaPlanMapper chaPlanMapper;

    @Autowired
    @Lazy
    TaskMapper taskMapper;

    @Autowired
    @Lazy
    IEduQuarterService iEduQuarterService;

    @Override
    public ChaPlan getPassRadeDetail(
            String yearPart,
            String quarterNum,
            String classTypeId,
            String readingType,
            String passType,
            String courseVersionId,
            String passDate,
            String passDateStart,
            String passDateEnd,
            String subjectsId,
            String rightNumStartDate,
            String rightNumEndDate,
            String radeType,
            String listState,
            String inType,
            Integer taskCategoryId,
            Long studentId) {

        if (StringUtils.isBlank(courseVersionId)) {
            courseVersionId = "1676874588501311488";//暂时默认
        }

        // 获取本学期最大的任务课次
        Task task = taskMapper.getTaskOneBackTaskNum(yearPart, quarterNum, Long.parseLong(courseVersionId), subjectsId, taskCategoryId);


        EduQuarter quarter = iEduQuarterService.getNowQuarter();
        String isBeforQuarter = "1";//是否之前学期1是，0否
        if (quarter != null) {
            //当前学期
            if (yearPart.equals(quarter.getYearPart().toString()) && quarterNum.equals(quarter.getNum().toString())) {
                isBeforQuarter = "0";
            }
        }

        return chaPlanMapper.getPassRadeDetail(yearPart, quarterNum, "1", String.valueOf(task.getTaskCourseNum()), classTypeId, readingType, passType, Long.parseLong(courseVersionId), passDate, passDateStart, passDateEnd, Long.parseLong(subjectsId), isBeforQuarter, "", "", "2", listState, null, inType, taskCategoryId, studentId);
    }


}
